Computer programs often use asynchronous mechanisms to perform tasks that may take a long time to complete, relative to CPU processing speeds. Examples of this are reading or writing to a disk, communicating with a remote computer, or querying a database. Asynchronous operations allow a user interface to remain responsive while the application performs other work or waits for an event to occur.
An asynchronous workflow is a construct that enables a program to perform asynchronous operations without blocking threads. The F# programming language provides mechanisms that allow a program to include asynchronous workflow. A program may, for example, specify a first operation such as a Web request and a second operation, such as processing the result that is received. This may be implemented by beginning execution of the first operation, and placing the second operation on a continuation. The continuation has a corresponding callback function, so that when the first operation completes, the callback function is invoked and the second operation executes. In this way, the thread upon which the first operation is executing can be released while the operation is waiting, and reused for another operation. This allows more operations to be invoked than there are threads. It also synchronizes the first and second operations, so that the second operation is suspended until the first operation completes.